//
//  NetTools.swift
//  StudyDY
//
//  Created by yinchangming on 2018/7/5.
//  Copyright © 2018年 yinchangming. All rights reserved.
//

import UIKit
import Alamofire
class NetTools {
    class func  requsetData(urlStr : String,type:HTTPMethod,params:Parameters?=nil,callBack : @escaping (_ result:Any) ->()){
        //https://www.jianshu.com/p/068eeb72439a 查看Alamofire的使用
        let url = urlStr
        let method: HTTPMethod = type == .get ? .get : .post
 
        let encoding: URLEncoding = .default
        let headers: HTTPHeaders = ["Content-Type": "application/json"]
        Alamofire.request(url, method: method, parameters: params, encoding: encoding, headers: headers).responseJSON { (respose) in
            guard  let result =  respose.result.value else {
                print ("请求错误\(String(describing: respose.result.error))")
                return
            }
            callBack(result)
        }
    }
}
